package bagu.juc.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolDemo01 {
    // 线程池大小为3，即最多有3个线程同时执行任务
    private static final ExecutorService ex = Executors.newFixedThreadPool(3);
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            int taskNumber = i + 1;
            ex.submit(()->{
                String threadName = Thread.currentThread().getName();
                System.out.println
                        ("task-" + taskNumber + "is being executed by thread-" +threadName );
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
        }
        ex.shutdown();
    }
}
